import 'package:flutter/material.dart';
// import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';

class SwiperDemo extends StatefulWidget {
  const SwiperDemo({Key? key}) : super(key: key);

  @override
  _SwiperDemoState createState() => _SwiperDemoState();
}

class _SwiperDemoState extends State<SwiperDemo> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: SwiperView(),
    );
  }
}

class SwiperView extends StatefulWidget {


   const SwiperView({Key? key}) : super(key: key);

  @override
  _SwiperViewState createState() => _SwiperViewState();
}

class _SwiperViewState extends State<SwiperView> {


  List _imgs= [
    {'url':'https://www.itying.com/images/flutter/1.png'},
    {'url':'https://www.itying.com/images/flutter/2.png'},
    {'url':'https://www.itying.com/images/flutter/3.png'},
    {'url':'https://www.itying.com/images/flutter/4.png'},
  ];

  @override
  Widget build(BuildContext context) {
    return Column(

      children: [

        Container(

          child: AspectRatio(
            aspectRatio: 16/9,
            child: Swiper(
              itemBuilder: (BuildContext context,int index){
                return new Image.network(_imgs[index]['url'],fit: BoxFit.fill,);
              },
              itemCount: _imgs.length,
              loop: true,//无限轮播模式开关
              autoplay: true,//自动轮播
              pagination: new SwiperPagination(),//底部原点按钮
              control: new SwiperControl(),//左右箭头
            ),
          )

        )


      ],
    );
  }
}
